<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StudentRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return $this->user()->can('create-edit-data');
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'certificates_type' => 'required',
            'id_card' => 'required',
            'mobile' => ['required', 'regex:/^1(3|4|5|7|8)[0-9]{9}$/'],
            'province_id' => 'required',
            'city_id' => 'required',
            'school_id' => 'required',
            'dept_id' => 'required',
            'speciality_id' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '姓名必填',
            'certificates_type.required' => '证件类型必填',
            'id_card.required' => '证件号码必填',
            'mobile.required' => '手机号必填',
            'mobile.regex' => '手机号格式有误',
            'province_id.required' => '省份必填',
            'city_id.required' => '城市必填',
            'school_id.required' => '学校必填',
            'dept_id.required' => '学院必填',
            'speciality_id.required' => '专业必填',
        ];
    }
}
